home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility3 / jfklib.zip / MSGLOOP.CPP < prev    next >
Text File  |  1991-05-11  |  2KB  |  122 lines

  1. /*
  2.     MSGLOOP.CPP - Die Windows-Nachrichtenschleife
  3.     (C) 1990 by Joachim Kainz 'On a mission from Bhudda'
  4. */
  5.     #include "msgloop.hpp"
  6.     #include <string.h>
  7.  
  8.     void EXPORT MSGLOOP::ProcessMsg (LPMSG lpMsg)
  9.     {
  10.         if (IsMDILoop ())
  11.             if (TranslateMDISysAccel (GetMDIClient (), lpMsg))
  12.                 return;
  13.  
  14.         for (WORD m=0; m<wDlg; m++)
  15.             if (IsDialogMessage (phDlg [m], lpMsg))
  16.                 return;
  17.  
  18.         TranslateMessage (lpMsg);
  19.         DispatchMessage  (lpMsg);
  20.     }
  21.  
  22.     int EXPORT MSGLOOP::Loop ()
  23.     {
  24.         MSG msg;
  25.  
  26.         while (GetMessage (&msg, NULL, NULL, NULL))
  27.             ProcessMsg (&msg);
  28.  
  29.         return msg.wParam;
  30.     }
  31.  
  32.     int EXPORT MSGLOOP::Peek ()
  33.     {
  34.         MSG msg;
  35.  
  36.         if (!PeekMessage (&msg, NULL, NULL, NULL, PM_REMOVE))
  37.             return FALSE;
  38.  
  39.         ProcessMsg (&msg);
  40.  
  41.         return TRUE;
  42.     }
  43.  
  44.     BOOL EXPORT MSGLOOP::SetMDIMode (HWND hwnd, HWND hmdiClient)
  45.     {
  46.         hWnd        = hwnd;
  47.         hMDIClient    = hmdiClient;
  48.  
  49.         return TRUE;
  50.     }
  51.  
  52.     EXPORT MSGLOOP::MSGLOOP ()
  53.     {
  54.         memset (this, 0, sizeof *this);
  55.     }
  56.  
  57.     EXPORT MSGLOOP::~MSGLOOP ()
  58.     {
  59.         if (wMaxDlg)
  60.             delete phDlg;
  61.     }
  62.  
  63.     BOOL EXPORT MSGLOOP::AddDlg (HWND hDlg)
  64.     {
  65.         if (wMaxDlg <= wDlg) {
  66.  
  67.             if (wMaxDlg) {
  68.  
  69.                 HWND * pNewDlg = new HWND [wMaxDlg+2];
  70.  
  71.                 if (!pNewDlg)
  72.                     return FALSE;
  73.  
  74.                 memmove (pNewDlg, phDlg, wDlg*sizeof (HWND));
  75.  
  76.                 delete phDlg;
  77.  
  78.                 phDlg = pNewDlg;
  79.  
  80.             } else
  81.                 phDlg = new HWND [wMaxDlg+2];
  82.  
  83.             wMaxDlg = LocalSize ((HANDLE) phDlg)/sizeof (HWND);
  84.  
  85.         }
  86.  
  87.         if (!phDlg)
  88.             return FALSE;
  89.  
  90.         phDlg [wDlg++] = hDlg;
  91.  
  92.         return TRUE;
  93.     }
  94.  
  95.     BOOL EXPORT MSGLOOP::RemoveDlg (HWND hDlg)
  96.     {
  97.         if (!wMaxDlg)
  98.             return TRUE;
  99.  
  100.         if (!hDlg) {
  101.  
  102.             delete phDlg;
  103.  
  104.             wDlg    =
  105.             wMaxDlg    = 0;
  106.  
  107.             return TRUE;
  108.  
  109.         }
  110.  
  111.         for (WORD m=0; m<wDlg; m++)
  112.             if (phDlg [m] == hDlg) {
  113.  
  114.                 wDlg--;
  115.                 memmove (phDlg+m, phDlg+m+1, wDlg-m);
  116.                 return TRUE;
  117.  
  118.             }
  119.  
  120.         return FALSE;
  121.     }
  122.